#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;
int main()
{
    string str1, str2;
    vector<vector<bool> > dp;
    while(cin >> str1 >> str2)
    {
        dp.resize(str1.size() + 1,vector<bool>(str2.size() + 1, false));
        dp[0][0] = true;
        for(int i = 1; i <= str1.size(); ++i)
        {
            for(int j = 1; j <= str2.size(); ++j)
            {
                if(str1[i-1] == str2[j-1] || str1[i-1] == '?')
                    dp[i][j] = dp[i-1][j-1];
                else if(str1[i-1] == '*')
                    dp[i][j] = dp[i-1][j-1] || dp[i-1][j] || dp[i][j-1];
                else
                    dp[i][j] = false;
            }
        }
        cout << dp[str1.size()][str2.size()] << endl;
    }
    return 0;
}